package com.geostar.constructionland.analyse.entity.alyresult.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.geostar.constructionland.analyse.entity.alyresult.AlyResult;
import com.geostar.constructionland.analyse.entity.alyresult.AnalysisNormalResult;
import com.geostar.constructionland.analyse.entity.alyresult.AnalysisResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yelll
 * @since 2020-6-2 11:20
 **/
@Component
@Slf4j
public class AlyResultDeserializer extends JsonDeserializer<AnalysisNormalResult> {

    @Override
    public AnalysisNormalResult deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        log.info(jsonParser.getCurrentName());
        //得到 codec， 通过调试可以知道，ta是一个 object mapper 对象
        ObjectCodec codec = jsonParser.getCodec();
        //读出所有的字段，得到 TreeNode 对象
        TreeNode readValueAsTree = jsonParser.readValueAsTree();
        //得到某个属性 的 node
        AnalysisNormalResult normalResult = new AnalysisNormalResult();
        normalResult.setResultRecords(readValueAsTree.toString());
        return normalResult;
    }
}
